package actions;

import java.sql.SQLException;
import java.util.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.StudentModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
//import forms.StudentForm;
import model.AdminModel;

public class AdminGetSpecializationsAction extends Action {

	private static final boolean DEBUG = true;

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws DbException {
		
		String path = mapping.getPath();
		
		if (DEBUG) {
			System.err.println("AdminGetSpecializationsAction: " + path);
		}
		
		// Retrieve all specializations
		RowSet specializationSet = AdminModel.getAllSpecializations();
		Vector<String> specializationVector = new Vector<String>();
		// Store all the specializations into a vector
		try {
		while(specializationSet.next())
		{
			specializationVector.add(specializationSet.getString(1));
			
		} } catch (SQLException e) {
			throw new DbException(e);
		}
		
		// Store the Vector in the request scope
		request.setAttribute("specializationVector", specializationVector);
		
		// Get the values for each specialization 
		Vector<String> specializationValues = AdminModel.getSpecializationValues();
		
		request.setAttribute("specializationValues", specializationValues);
		
		
		return mapping.findForward("success");
	}
}